home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_05 / saks / lns1b.cpp < prev    next >
C/C++ Source or Header  |  1994-03-08  |  631b  |  37 lines

  1. Listing 7 - member function definitions for lns using a pair of pointers
  2.  
  3. //
  4. // lns1b.cpp - line number sequence implementation
  5. //
  6. #include <stdio.h>
  7.  
  8. #include "lns.h"
  9.  
  10. lns::lns(unsigned n)
  11.     {
  12.     first = last = new node(n);
  13.     }
  14.  
  15. lns::~lns()
  16.     {
  17.     node *p;
  18.     while ((p = first) != 0)
  19.         {
  20.         first = first->next;
  21.         delete p;
  22.         }
  23.     }
  24.  
  25. void lns::add(unsigned n)
  26.     {
  27.     if (last->number != n)
  28.         last = last->next = new node(n);
  29.     }
  30.  
  31. void lns::print()
  32.     {
  33.     node *p;
  34.     for (p = first; p != 0; p = p->next)
  35.         printf(" %4d", p->number);
  36.     }
  37.